package com.wtf.dsp.admin.controller;


import com.wtf.dsp.admin.model.dto.*;
import com.wtf.dsp.admin.service.UserService;
import com.wtf.dsp.core.api.R;
import com.wtf.dsp.core.util.PageUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName: UserController
 * Description:
 * date: 2023/8/3 18:26
 *
 * @author linhuanyou
 * @version 1.0
 */
@Api(tags = "用户管理")
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation(value = "获取用户列表(分页)")
    @GetMapping("/page")
    public R<PageUtils> page(@Validated UserPageDTO userPageDTO){
        PageUtils pageUtils = userService.page(userPageDTO);
        return R.ok(pageUtils);
    }

    @ApiOperation(value = "新增用户")
    @PostMapping("/add")
    public R add(@RequestBody @Validated UserAddDTO userAddDTO){
        int add = userService.add(userAddDTO);
        return R.ok();
    }

    @ApiOperation(value = "删除用户")
    @PostMapping("/del")
    public R remove(@RequestBody @Validated UserDelDTO userDelDTO){
        int del = userService.remove(userDelDTO);
        return R.ok();
    }

    @ApiOperation(value = "编辑密码")
    @PostMapping("/updatePwd")
    public R update(@RequestBody @Validated UserUpdateDTO userUpdateDTO){
        int update = userService.update(userUpdateDTO);
        return R.ok();
    }
}
